package com.bwc.aidemo.arouter

import android.os.Parcelable
import com.alibaba.android.arouter.launcher.ARouter
import java.io.Serializable

/**
 * ARouter跳转
 */
object ARouterHelper {
    /**
     * 通过ARouter跳转并传递参数
     * @param path 路由地址
     * @param params 参数（键值对形式）
     */
    fun navigate(path: String?, params: Map<String, Any>?) {
        val postcard = ARouter.getInstance().build(path)
        if (params != null) {
            for ((key, value) in params) {
                if (value is String) {
                    postcard.withString(key, value)
                } else if (value is Int) {
                    postcard.withInt(key, value)
                } else if (value is Boolean) {
                    postcard.withBoolean(key, value)
                } else if (value is Float) {
                    postcard.withFloat(key, value)
                } else if (value is Long) {
                    postcard.withLong(key, value)
                } else if (value is Parcelable) {
                    postcard.withParcelable(key, value)
                } else if (value is Serializable) {
                    postcard.withSerializable(key, value)
                }
                // 你可以根据需要继续添加其他数据类型的支持
            }
        }
        postcard.navigation() // 跳转
    }
}